import { forwardRef, useState } from "react";
import { Button, Drawer, message } from "antd";
import { ProTable } from "@ant-design/pro-components";
import { calcColumns2 } from "../configFile";
import Https from "@/utils/Https";
import dayjs from "dayjs";

export default forwardRef((props, ref) => {
  const { classInfo, defaultTime } = props;
  const [loading, setLoading] = useState(false);
  const getList = async (params) => {
    setLoading(true);
    let res = await Https.post(
      "/wechatusercard/userCardList",
      {
        ...params,
        status: 3,
        vipcardId: classInfo.id,
        effectiveStartTime:
          dayjs(defaultTime).format("YYYY-MM-DD") + " " + "00:00:00",
      },
      true
    );
    setLoading(false);
    let records = [];
    let total = 0;
    if (res.code == 200 && res.data) {
      records = res.data.records;
      total = res.data.total;
    } else {
      message.error(res.msg);
    }
    return {
      success: true,
      data: records,
      total: total,
    };
  };
  return (
    <Drawer
      width="60%"
      open={props.show}
      title="选择学员"
      destroyOnClose={true}
      onClose={() => props.close()}
    >
      <ProTable
        //toolBarRender={false}
        pagination={{
          showSizeChanger: true,
        }}
        rowKey="id"
        search={false}
        loading={loading}
        request={async (params) => {
          return await getList(params);
        }}
        columns={calcColumns2({
          operate: {
            title: "操作",
            fixed: "right",
            dataIndex: "id",
            align: "center",
            width: "100",
            hideInSearch: true,
            render: (_, record) => {
              return (
                <Button type="link" onClick={() => props.submit(record)}>
                  选择
                </Button>
              );
            },
          },
        })}
      />
    </Drawer>
  );
});
